# Create your views here.
from django.shortcuts import get_object_or_404,render_to_response
from django.http import HttpResponse,HttpResponseRedirect
from django.http import Http404
from django.core.urlresolvers import reverse
from django.db.models import Q
from datetime import datetime
from demo.task.models import Task
from demo.task.models import Type
from demo.task.models import Project

def index(request):
	#task_list = Task.objects.filter(status = 0).order_by('-created_on')[:15]
	task_list = Task.objects.all().order_by('-created_on')[:15]
	return render_to_response('task/index.html',
		{'task_list':task_list,})
def send(request):
	if request.POST.has_key('mission'):
		tp = Type.objects.all()[0]
		pj = Project.objects.all()[0]
		task_name = request.POST.get('mission','none')
		task_private = request.POST.get('is_public',False)
		#new_task = Task(name = task_name,is_private = task_private,type = 0,project = 0)
		new_task = Task(name = task_name,description = '',type = tp,is_private = task_private,created_on = datetime.now(),edited_on = datetime.now(),completed_on = datetime.now(),project = pj,file = '',status = 0,user_id = 0)
		new_task.save()
		return HttpResponseRedirect('/task/')

'''
	#used get method
	query = request.GET.get('t',"")
	if query:
		new_entry = Entry(content = query)
		new_entry.save()
	entry_list = Entry.objects.all().order_by('-published_at')[:15]
	return render_to_response("exposure/index.html",{"entry_list":entry_list,"query":query,})
'''
